<?php
if(isset($_SESSION['admin'])) {
	if($_SESSION['admin']) {
		include("_gestionBase.inc.php");
		include("_controlesEtGestionErreurs.inc.php");

		// CONNEXION AU SERVEUR MYSQL PUIS SÉLECTION DE LA BASE DE DONNÉES

		$tabErreurs = array();

		$connexion=connect();
		if (!$connexion)
		{
			ajouterErreur($tabErreurs, "Echec de la connexion au serveur MySql");
			afficherErreurs($tabErreurs);
			exit();
		}
		if (!selectBase($connexion))
		{
			ajouterErreur($tabErreurs, "La base de données stsig est inexistante ou non accessible");
			afficherErreurs($tabErreurs);
			exit();
		}
		mysql_select_db("histostages", $connexion);
		?>
<form id="modifOrga" action="" method="post">
	<select name="nomOrga" id="nomOrga" placeholder="Nom">
		<?php 
		$connexion=connect();
		selectBase($connexion);

		$req = "select nom from organisation order by nom asc";
		$rsOrga = mysql_query($req, $connexion);
		$lgOrga = mysql_fetch_assoc($rsOrga);
		$libelle = $lgOrga['nom'];
		for ($i = 0; $i < mysql_num_rows($rsOrga) ;$i++ )
		{
			?>
		<option value="<?php echo $libelle ?>">
			<?php echo $libelle = $lgOrga['nom'] ?>
		</option>
		<?php
		$lgOrga = mysql_fetch_assoc($rsOrga);
		}
			
		mysql_free_result($rsOrga);
		?>
	</select></br> </br> 
	<input type="text" name="adresseOrga"
		placeholder="Adresse" required=required /></br> </br> <input
		type="text" name="cpOrga" placeholder="Code Postal" required=required /></br>
	</br> <input type="text" name="villeOrga" placeholder="ville"
		required=required /></br> </br> <input type="text" name="telOrga"
		placeholder="Téléphone" required=required /></br> </br> <input
		type="email" name="emailOrga" placeholder="Email" required=required /></br>
	</br> <input type="text" name="siteOrga" placeholder="Site Web"
		required=required /></br> </br> <input type="submit" />
</form>
<?php 
mysql_connect("localhost","stssio","stssio");
mysql_select_db("histostages");

$nom = (isset($_POST['nomOrga'])) ? $_POST['nomOrga'] : '';
$adresseOrga = (isset($_POST['adresseOrga'])) ? $_POST['adresseOrga'] : '';
$cpOrga = (isset($_POST['cpOrga'])) ? $_POST['cpOrga'] : '';
$villeOrga = (isset($_POST['villeOrga'])) ? $_POST['villeOrga'] : '';
$telOrga = (isset($_POST['telOrga'])) ? $_POST['telOrga'] : '';
$emailOrga = (isset($_POST['emailOrga'])) ? $_POST['emailOrga'] : '';
$siteOrga = (isset($_POST['siteOrga'])) ? $_POST['siteOrga'] : '';

if(isset($_POST['nomOrga'])) {
	modifierOrga($connexion, $nom, $adresseOrga, $cpOrga, $villeOrga, $telOrga, $emailOrga, $siteOrga);
	mysql_close();
	echo 'Organisation modifiée !';
}
mysql_close($connexion);
		
	}
} 
else {
	echo 'vous n\'êtes pas connecté!';
}
?>